package com.github.zhp.startup;

import com.baomidou.mybatisplus.generator.config.OutputFile;

import java.io.File;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * config.json中的配置
 *
 * @author zhoup
 */
public class ConfigJson {
    /**
     * 作者
     */
    private String author = "zhp";
    /**
     * packageName
     */
    private String packageName = "com.example";
    /**
     * 模块名称
     */
    private String moduleName = "";
    /**
     * 代码输出目录
     */
    private String outPutDir = null;
    /**
     * 数据库连接
     */
    private String databaseUrl = "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;CASE_INSENSITIVE_IDENTIFIERS=TRUE";
    /**
     * 数据库用户名
     */
    private String userName = "sa";
    /**
     * 数据库密码
     */
    private String password = "";
    /**
     * 需要生成代码的表
     */
    private String includes = "t_simple";
    /**
     * 待使用的模版引擎
     */
    private TemplateEngineType templateEngineType = TemplateEngineType.freemarker;
    /**
     * 模版的基本路径
     */
    private String baseTemplatePath;
    /**
     * controller模板路径
     */
    private String controllerTemplatePath = "/templates/ExampleController.java";
    /**
     * 模板路径
     */
    private String entityTemplatePath = "/templates/Example.java";
    /**
     * 模板路径
     */
    private String mapperTemplatePath = "/templates/ExampleMapper.java";
    /**
     * 模板路径
     */
    private String mapperXmlTemplatePath = "/templates/ExampleMapper.xml";
    /**
     * 模板路径
     */
    private String serviceTemplatePath = "/templates/ExampleService.java";
    /**
     * 模板路径
     */
    private String serviceImplTemplatePath = "/templates/ExampleServiceImpl.java";
    /**
     * 读取sql文件中的表进行代码生成
     */
    private String sqlFilePath = "D:\\code\\gitee\\java\\ztools\\generator-develop\\mybatis-plus-generator\\src\\test\\resources\\sql\\init.sql";
    /**
     * 是否使用sql文件的方式生成代码
     */
    private boolean useSql = true;
    /**
     * 是否生成控制类
     */
    private boolean genController = true;
    /**
     * 是否生成实体类
     */
    private boolean genEntity = true;
    /**
     * 是否生成mapper类
     */
    private boolean genMapper = true;
    /**
     * 是否生成xml文件
     */
    private boolean genMapperXml = true;
    /**
     * 是否生成service
     */
    private boolean genService = true;
    /**
     * 是否生成serviceImpl
     */
    private boolean genServiceImpl = true;

    private Map<OutputFile, String> pathInfoMap = new LinkedHashMap<>();

    public String getSqlFilePath() {
        return sqlFilePath;
    }

    public void setSqlFilePath(String sqlFilePath) {
        this.sqlFilePath = sqlFilePath;
    }

    public boolean isUseSql() {
        return useSql;
    }

    public void setUseSql(boolean useSql) {
        this.useSql = useSql;
    }

    public String getControllerTemplatePath() {
        return controllerTemplatePath;
    }

    public void setControllerTemplatePath(String controllerTemplatePath) {
        this.controllerTemplatePath = controllerTemplatePath;
    }

    public String getEntityTemplatePath() {
        return entityTemplatePath;
    }

    public void setEntityTemplatePath(String entityTemplatePath) {
        this.entityTemplatePath = entityTemplatePath;
    }

    public String getMapperTemplatePath() {
        return mapperTemplatePath;
    }

    public void setMapperTemplatePath(String mapperTemplatePath) {
        this.mapperTemplatePath = mapperTemplatePath;
    }

    public String getMapperXmlTemplatePath() {
        return mapperXmlTemplatePath;
    }

    public void setMapperXmlTemplatePath(String mapperXmlTemplatePath) {
        this.mapperXmlTemplatePath = mapperXmlTemplatePath;
    }

    public String getServiceTemplatePath() {
        return serviceTemplatePath;
    }

    public void setServiceTemplatePath(String serviceTemplatePath) {
        this.serviceTemplatePath = serviceTemplatePath;
    }

    public String getServiceImplTemplatePath() {
        return serviceImplTemplatePath;
    }

    public void setServiceImplTemplatePath(String serviceImplTemplatePath) {
        this.serviceImplTemplatePath = serviceImplTemplatePath;
    }

    public String getDatabaseUrl() {
        return databaseUrl;
    }

    public void setDatabaseUrl(String databaseUrl) {
        this.databaseUrl = databaseUrl;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getIncludes() {
        return includes;
    }

    public void setIncludes(String includes) {
        this.includes = includes;
    }

    public String getOutPutDir() {
        String defaultValue = "src/main/java";
        if (outPutDir == null || outPutDir.isEmpty()) {
            String userDir = System.getProperty("user.dir");
            if (moduleName != null) {
                outPutDir = userDir
                        + File.separator
                        + moduleName
                        + File.separator + "src"
                        + File.separator + "main"
                        + File.separator + "java";

            } else {
                outPutDir = userDir
                        + File.separator + "src"
                        + File.separator + "main"
                        + File.separator + "java";
            }
        }
        return outPutDir;
    }

    public void setOutPutDir(String outPutDir) {
        this.outPutDir = outPutDir;
    }

    public String getModuleName() {
        return moduleName;
    }

    public void setModuleName(String moduleName) {
        this.moduleName = moduleName;
    }

    public String getPackageName() {
        return packageName;
    }

    public void setPackageName(String packageName) {
        this.packageName = packageName;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public boolean isGenController() {
        return genController;
    }

    public void setGenController(boolean genController) {
        this.genController = genController;
    }

    public boolean isGenEntity() {
        return genEntity;
    }

    public void setGenEntity(boolean genEntity) {
        this.genEntity = genEntity;
    }

    public boolean isGenMapper() {
        return genMapper;
    }

    public void setGenMapper(boolean genMapper) {
        this.genMapper = genMapper;
    }

    public boolean isGenMapperXml() {
        return genMapperXml;
    }

    public void setGenMapperXml(boolean genMapperXml) {
        this.genMapperXml = genMapperXml;
    }

    public boolean isGenService() {
        return genService;
    }

    public void setGenService(boolean genService) {
        this.genService = genService;
    }

    public boolean isGenServiceImpl() {
        return genServiceImpl;
    }

    public void setGenServiceImpl(boolean genServiceImpl) {
        this.genServiceImpl = genServiceImpl;
    }

    public Map<OutputFile, String> getPathInfoMap() {
        return pathInfoMap;
    }

    public void setPathInfoMap(Map<OutputFile, String> pathInfoMap) {
        this.pathInfoMap = pathInfoMap;
    }

    public String getBaseTemplatePath() {
        return baseTemplatePath;
    }

    public void setBaseTemplatePath(String baseTemplatePath) {
        this.baseTemplatePath = baseTemplatePath;
    }

    public TemplateEngineType getTemplateEngineType() {
        return templateEngineType;
    }

    public void setTemplateEngineType(TemplateEngineType templateEngineType) {
        this.templateEngineType = templateEngineType;
    }
}
